Setter & Getter

image.png

原本取用方式:

//建立student物件stu
Student stu = new Student();
//設定年齡為23
stu.age = 23;

這種作法的問題為:
如果年齡給為負數,有機會造成其他 function 的錯誤

所以改用 Getter & Setter 方式